package day04;

import java.util.Scanner;
import org.junit.Test;

public class demo2 {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入教师个数：");
		int num = scanner.nextInt();
		Teacher[] teachers = new Teacher[num];
		for (int i = 0; i < teachers.length; i++) {
			System.out.println("请输入教师id:");
			int id = scanner.nextInt();
			System.out.println("请输入教师名字：");
			String name = scanner.next();
			System.out.println("请输入教师年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入教师班级：");
			String className = scanner.next();
			System.out.println("请输入教师收入：");
			int salary = scanner.nextInt();
			Teacher teacher = new Teacher(id, salary, age, name, className);
			//teacher.setId(id);
			//teacher.setName(name);
			//teacher.setAge(age);
			//teacher.setClassName(className);
			//teacher.setSalary(salary);
			
			teachers[i] = teacher;
			
		}
		for (int i = 0; i < teachers.length; i++) {
			
			Teacher teacher = teachers[i];
			//输出，引用函数tostring
			System.out.println(teacher.toString());
			
		}
		
		
		
		
		while(true) {
			System.out.println("-----------------");
			System.out.println("依据id查找请输入1：");
			System.out.println("依据姓名查找请输入2：");
			System.out.println("依据年龄查找请输入3；");
			System.out.println("依据班级查找请输入4:");
			System.out.println("依据薪水查找请输入5：");
			System.out.println("退出请输入0");
			System.out.println("-----------------");
			int type = scanner.nextInt();
			if(type == 0) {
				System.out.println("退出");
				break;
				
			}
			
			switch(type) {
			case 1:
				System.out.println("请输入需要查找的老师id：");
				boolean isExistId = false;
				for (int i = 0; i < teachers.length; i++) {
					int id = scanner.nextInt();
					Teacher teacher = teachers[i];
					if (teacher.getId() == id) {
						isExistId = true;
						System.out.println(teacher.toString());
					}
					
				}
				if (isExistId == false) {
					System.out.println("查不到此人信息");
				}
				break;
			case 2:
				System.out.println("请输入需要查找的老师名字：");
				boolean isExistName = false;//bool假设找不到
				for (int i = 0; i < teachers.length; i++) {
					String name = scanner.next();//对应输出的字符串
					Teacher teacher = teachers[i];//将对象从数组中拿出来
					if (name.equals(teacher.getName())) {//比较用equals：变量.equals（）括号里用get函数方法调用						
						
						isExistName = true;//存在即需要输出对象信息
						System.out.println(teacher.toString());
					}
					
				}//结束循环判定是否boolean类型结果是否发生变化
				if (isExistName == false) {
					System.out.print("查无此人信息");
				}
				break;
			case 3:
				System.out.println("请输入需要查找的老师年龄：");
				boolean isExistAge = false;
				for (int i = 0; i < teachers.length; i++) {
					Teacher teacher = teachers[i];
					int age = scanner.nextInt();
					if (teacher.getAge() == age) {
						isExistAge = true;
						System.out.print(teacher.toString());
					}
				}
				if (isExistAge == false) {
					System.out.print("查无此人信息");
				}
				break;
			case 4:
				System.out.print("请输入需要查找的老师班级：");
				boolean isExistClassName = false;
				for (int i = 0; i < teachers.length; i++) {
					Teacher teacher = teachers[i];
					String className = scanner.next();
					
					if (className.equals(teacher.getClassName())) {
						
						System.out.print(teacher.toString());
					}
				}
				if (isExistClassName == false) {
					
					System.out.println("查无此人");
					
				}
				break;
			case 5:
				System.out.println("请输入需要查找老师的薪水：");
				boolean isExistSalary = false;
				for (int i = 0; i < teachers.length; i++) {
					Teacher teacher = teachers[i];
					int salary = scanner.nextInt();
					if (teacher.getSalary() == salary) {
						isExistSalary = true;
						System.out.print(teacher.toString());
						
					}
				}
				if (isExistSalary == false) {
					System.out.print("查无此人");
				}
				break;
			default:
				break;
				
				
			}
			
		}
  }
}
		
		
		
		
		
		
		
		
		
		